var crypto = require('crypto');

class HashUtils {
  
  static md5(content) {
    return HashUtils.getHash(content, "MD5");
  }

  static sha1(content) {
    return HashUtils.getHash(content, "SHA1");
  }
  
  static sha256(content) {
    return HashUtils.getHash(content, "SHA256");
  }
  
  static sha512(content) {
    return HashUtils.getHash(content, "SHA512");
  }
  
  static getHash(content, type) {
    var encodeStr = "";
    try {
      var md5 = crypto.createHash(type);
      //内容
      md5.update(content);
      encodeStr = md5.digest('hex');
    } catch (e) {
      console.log(e);
    }
    return encodeStr;
  }

}
module.exports = HashUtils;